package zhcms.framework.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import zhcms.framework.GyReplace;
import zhcms.framework.GySplit;


public class GyFor {
	
	// 得到所有的for标签
	private String returnS;
	private String currnS;
	
	public GyFor()
	{
		returnS="";
	}
	
	public void setContent(String content){
		this.currnS=content;
	}
	
	/*public void ParseFor(String gytFrontSeparator,String gytBackSeparator,HashMap<String, ArrayList<HashMap<String, String>>> gytInFor)
	{
		//查找是否还有多层for
		
		String[] tempContent = null;
		GySplit h = new GySplit();
		h.tool(this.currnS, gytFrontSeparator+"for:");
		tempContent = h.Show();
		h = null;
	
		if(tempContent.length<2)
		{
			//1没有for，直接返回字符串
			this.returnS=this.currnS;
		}
		else
		{
			//2.存在for，进行处理
			//只处理一层的for
			//得到for 的个数
			returnS=tempContent[0];
			
			String[] tempMidContent = null;
			GySplit a = new GySplit();
			a.tool(tempContent[1], gytBackSeparator);
			tempMidContent = a.Show();
			a = null;
			//得到关键字
			String forKeyWord=tempMidContent[0];
			
			
			//得到中间的内容
			String[] tempMidContentMain = null;
			GySplit b = new GySplit();
			b.tool(this.currnS, gytFrontSeparator+"endfor:"+forKeyWord+gytBackSeparator);
			tempMidContentMain = b.Show();
			b = null;
			
			String tempMidContentTrueMainFalse=tempMidContentMain[0];
			String tempMidContentTrueMain="";
			
			
			String[] tempMidContentMainArray = null;
			GySplit m = new GySplit();
			m.tool(tempMidContentTrueMainFalse, gytFrontSeparator+"for:"+forKeyWord+gytBackSeparator);
			tempMidContentMainArray = m.Show();
			m = null;
			
			tempMidContentTrueMain=tempMidContentMainArray[1];
			//得到后续
			String tempFootContentTrueMain=tempMidContentMain[1];
			//对中间进行处理，如果存在，继续，不存在处理for后返回
			//System.out.println("[["+ tempFootContentTrueMain + "]");
			String[] TtempMidContentMain = null;
			GySplit c = new GySplit();
			c.tool(tempMidContentTrueMain, gytFrontSeparator+"for:");
			TtempMidContentMain = c.Show();
			c = null;
			
			if(TtempMidContentMain.length<2)
			{
				GyGetFor ggf=new GyGetFor();
				ggf.setcurrnS(tempMidContentTrueMain);
				ggf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor, forKeyWord);
				returnS=returnS+ggf.getsContent();
			}
			else
			{
				GyFor gyf=new GyFor();
				gyf.setContent(tempMidContentTrueMain);
				gyf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor);
				returnS=returnS+gyf.getcurrnS();
			}
			
			//得到后续
			String[] TtempFootContentTrueMain = null;
			GySplit d = new GySplit();
			d.tool(tempFootContentTrueMain, gytFrontSeparator+"for:");
			TtempFootContentTrueMain = d.Show();
			d = null;
			if(TtempFootContentTrueMain.length<2)
			{
				returnS=returnS+tempFootContentTrueMain;
			}
			else
			{
				GyFor gyfo=new GyFor();
				gyfo.setContent(tempFootContentTrueMain);
				gyfo.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor);
				returnS=returnS+gyfo.getcurrnS();
			}
		}
	}*/
	
	@SuppressWarnings("unused")
	public void ParseFor(String gytFrontSeparator,String gytBackSeparator,HashMap<String, ArrayList<HashMap<String, String>>> gytInFor)
	{
		int NumFor=0;
		int maxDepth=0;
		String forhead="";
		String forfoot="";
		String SourceHtml="";
		SourceHtml=this.currnS;
		String[] tempContent = null;
		
		GyLinkTables head = null;
		GyLinkTables CL = new GyLinkTables();
		
		GySplit a = new GySplit();
		a.tool(this.currnS, gytFrontSeparator+"for:");
		tempContent = a.Show();
		a = null;
		//System.out.println("查看源代码：："+tempContent.length);
		//查找是否有for这个标签，如果没有的话，则跳过
		if(tempContent.length<=1)
		{
			this.returnS=this.currnS;
		}
		else
		{
			//修复取出尾部
			String[] tempContentfoot = null;
			GySplit z = new GySplit();
			z.tool(tempContent[(tempContent.length-1)], gytFrontSeparator+"endfor:");
			tempContentfoot = z.Show();
			z = null;
			//System.out.println("查看源代码：："+tempContent[(tempContent.length-1)]);
			//System.out.println("查看源代码1：："+tempContentfoot[1]);
			
			String[] tempContentfoot1 = null;
			GySplit z1 = new GySplit();
			z1.tool(tempContentfoot[1], gytBackSeparator);
			tempContentfoot1 = z1.Show();
			z1 = null;
			
			//System.out.println("查看源代码2：："+tempContentfoot1[0]);
			
			//System.out.println("查看源代码1：："+tempContent[(tempContent.length-1)]);
			//修复取出尾部
			String[] tempContentfoot2 = null;
			GySplit z2 = new GySplit();
			z2.tool(tempContent[(tempContent.length-1)], gytFrontSeparator+"endfor:"+tempContentfoot1[0]+gytBackSeparator);
			tempContentfoot2 = z2.Show();
			z2 = null;
			
			forhead=tempContent[0];
			forfoot=tempContentfoot2[1];
			//取尾巴的内容
			//System.out.println("尾巴的内容：："+forhead);
			//修复成功
			
			//
			NumFor=tempContent.length-1;
			for(int i=0;i<NumFor;i++)
			{
				String tempcuurS="";
				String keyword="";
				String Content="";
				//
				for(int j=i;j<NumFor;j++)
				{
					tempcuurS=tempcuurS+tempContent[j+1]+gytFrontSeparator+"for:";
				}
				
				//System.out.println("[[["+i+"]]]tempcuurS============"+tempcuurS);
				
				String[] tempContentB = null;
				GySplit b = new GySplit();
				b.tool(tempcuurS, gytBackSeparator);
				tempContentB = b.Show();
				b = null;
				keyword=tempContentB[0];
				//System.out.println("[[["+i+"]]]keyword============"+keyword);
				String[] tempContentC = null;
				GySplit c = new GySplit();
				c.tool(tempcuurS, gytFrontSeparator+"endfor:"+keyword+gytBackSeparator);
				tempContentC = c.Show();
				c = null;
				
				Content=tempContentC[0];
				
				GyReplace gyr=new GyReplace();
				Content=gyr.replaceAllNew1(Content, keyword+gytBackSeparator, "");
				
				//添加前先便利更新深度
				
				GyLinkTables htemp = null;
				GyForData tempnodeData ;
				htemp = head;
				
				int cdepth=0;
				
				while(htemp != null)							//循环处理链表每个结点
				{
					tempnodeData = htemp.nodeData;
					
					String[] tempContentD = null;
					GySplit d = new GySplit();
					d.tool(tempnodeData.content, gytFrontSeparator+"for:"+keyword+gytBackSeparator);
					tempContentD = d.Show();
					d = null;
					
					if(tempContentD.length<2)
					{
						
					}
					else
					{
						cdepth=cdepth+1;
						if(maxDepth>cdepth)
						{
							
						}
						else
						{
							maxDepth=cdepth;
						}
					}
					
					htemp = htemp.nextNode;
				}
				
				//System.out.println("[[["+i+"]]]keyword============"+keyword);
				//System.out.println("[[["+i+"]]]Content============"+Content);
				//System.out.println("[[["+i+"]]]cdepth============"+cdepth);
				GyForData nodeData = new GyForData();
				nodeData.id=i;
				nodeData.keyword=keyword;
				nodeData.content=Content;
				nodeData.depth=cdepth;
				head = CL.CLAddEnd(head, nodeData);//在链表尾部添加结点
			}
			//System.out.println("[[]]maxDepth============"+maxDepth);
			//CL.CLAllNode(head);
			
			//ArrayList<Map<String, String>> forb=new ArrayList<Map<String, String>>();
			GyArrayList[] tempfor;
			tempfor=new GyArrayList[(maxDepth+1)];
			for(int fi=maxDepth;fi>=0;fi--)
			{
				//System.out.println("[[[[[]]]]]]]]]]]]]+++++++"+fi);
				GyLinkTables forhtemp;
				GyForData fornodeData ;
				forhtemp = head;
				GyArrayList forMain=new GyArrayList();
				ArrayList<ArrayList<Map<String,String>>> forc=new ArrayList<ArrayList<Map<String,String>>>();
				while(forhtemp != null)							//循环处理链表每个结点
				{
					fornodeData = forhtemp.nodeData;
					//System.out.println("关键词["+fornodeData.keyword+"]");
					if(fornodeData.depth==fi)
					{
						if(fornodeData.depth==maxDepth)
						{
							//是最里层
							//只是循环，不做其它的处理
							ArrayList<Map<String,String>> forb=new ArrayList<Map<String,String>>();
							Map<String,String> fora=new HashMap<String,String>();
							//System.out.println("处理2");
							GyGetFor ggf=new GyGetFor();
							ggf.setcurrnS(fornodeData.content);
							//ggf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor, fornodeData.keyword);
							//对keyword进行判断，看看有没有步长
							if(fornodeData.keyword.indexOf("[")<0)
							{
								ggf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor, fornodeData.keyword);
							}
							else
							{
								
								String stepnum="0";
								String tkey="";
								//获取关键词和步长
								String[] tempStepMain = null;
								GySplit mm = new GySplit();
								mm.tool(fornodeData.keyword, "[");
								tempStepMain = mm.Show();
								mm = null;
								
								tkey=tempStepMain[0];
								stepnum=tempStepMain[1];
								
								String[] tempStepMain1 = null;
								GySplit mm1= new GySplit();
								mm1.tool(stepnum, "]");
								tempStepMain1 = mm1.Show();
								mm1 = null;
								
								stepnum=tempStepMain1[0];
								
								//System.out.println("步长"+stepnum);
								//
								ggf.ParseForStep(gytFrontSeparator, gytBackSeparator, gytInFor, tkey ,stepnum);
							}
							
							
							fora.put("content", ggf.getsContent());
							//System.out.println("处理2:::::::::::"+fornodeData.content);
							fora.put("oldcontent", fornodeData.content);
							fora.put("id", fornodeData.id+"");
							fora.put("keyword", fornodeData.keyword);
							fora.put("depth", fornodeData.depth+"");
							forb.add(fora);
							//forMain.setArrayList(fora);
							forc.add(forb);
						}
						else
						{
							//如果不是最里层
							//则先处理最和外层的关系
							//首先取得下一层中所有已经替换的数据
							//当前变量
							String cqcontent=fornodeData.content;
							String cqkeyword=fornodeData.keyword;
							int cqid=fornodeData.id;
							int cqdepth=fornodeData.depth;
							
							for(int forti=0;forti<tempfor[(fi+1)].getForArrayList().size();forti++)
							{
								//判断当前的变量中是否含有下一层中的关键词，即是否替换for变量
								ArrayList<Map<String,String>> ThFora=new ArrayList<Map<String,String>>();
								ThFora=tempfor[(fi+1)].getForArrayList().get(forti);
								for(int forthi=0;forthi<ThFora.size();forthi++)
								{
									HashMap<String, String> iThFora = (HashMap<String, String>) ThFora.get(forthi);
									
									String thcontent=iThFora.get("content");//替换过的内容，
									String tholdcontent=iThFora.get("oldcontent");//未替换的内容
									String thkeyword=iThFora.get("keyword");//关键词
									//System.out.println("查找"+gytFrontSeparator+"for:" +thkeyword +gytBackSeparator+"");
									String[] tempContentE = null;
									GySplit e = new GySplit();
									e.tool(cqcontent, gytFrontSeparator+"for:" +thkeyword +gytBackSeparator);
									tempContentE = e.Show();
									e = null;
									if(tempContentE.length<2)
									{
										//没有找到
									}
									else
									{
										//找到替换
										//System.out.println("把｛"+tholdcontent+"｝替换成【"+thcontent+"】");
										
										GyReplace r = new GyReplace();
										r.replaceAll(cqcontent, gytFrontSeparator+"for:" +thkeyword +gytBackSeparator+tholdcontent+gytFrontSeparator+"endfor:" +thkeyword +gytBackSeparator, thcontent);
										cqcontent=r.Show();
									}
									
								}
								
								
							}
							
							ArrayList<Map<String,String>> forb=new ArrayList<Map<String,String>>();
							Map<String,String> fora=new HashMap<String,String>();
							//System.out.println("处理2");
							GyGetFor ggf=new GyGetFor();
							ggf.setcurrnS(cqcontent);
							
							//对keyword进行判断，看看有没有步长
							if(fornodeData.keyword.indexOf("[")<0)
							{
								ggf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor, fornodeData.keyword);
							}
							else
							{
								
								String stepnum="0";
								String tkey="";
								//获取关键词和步长
								String[] tempStepMain = null;
								GySplit mm = new GySplit();
								mm.tool(fornodeData.keyword, "[");
								tempStepMain = mm.Show();
								mm = null;
								
								tkey=tempStepMain[0];
								stepnum=tempStepMain[1];
								
								String[] tempStepMain1 = null;
								GySplit mm1= new GySplit();
								mm1.tool(stepnum, "]");
								tempStepMain1 = mm1.Show();
								mm1 = null;
								
								stepnum=tempStepMain1[0];
								//
								ggf.ParseForStep(gytFrontSeparator, gytBackSeparator, gytInFor, tkey ,stepnum);
							}
							
							//ggf.ParseFor(gytFrontSeparator, gytBackSeparator, gytInFor, fornodeData.keyword);
							fora.put("content", ggf.getsContent());
							fora.put("oldcontent", fornodeData.content);
							fora.put("id", fornodeData.id+"");
							fora.put("keyword", fornodeData.keyword);
							fora.put("depth", fornodeData.depth+"");
							forb.add(fora);
							//forMain.setArrayList(fora);
							forc.add(forb);
						}
					}
					
					forhtemp = forhtemp.nextNode;
				}
				forMain.setArrayList(forc);
				tempfor[fi]=forMain;
			}
			this.returnS=forhead;
			
			//for(int tti=0;tti<(maxDepth+1);tti++)
			//{
				for(int forti=0;forti<tempfor[0].getForArrayList().size();forti++)
				{
					//判断当前的变量中是否含有下一层中的关键词，即是否替换for变量
					ArrayList<Map<String,String>> ThFora=new ArrayList<Map<String,String>>();
					ThFora=tempfor[(0)].getForArrayList().get(forti);
					for(int forthi=0;forthi<ThFora.size();forthi++)
					{
						HashMap<String, String> iThFora = (HashMap<String, String>) ThFora.get(forthi);
						
						String thcontent=iThFora.get("content");//替换过的内容，
						String tholdcontent=iThFora.get("oldcontent");//未替换的内容
						String thkeyword=iThFora.get("keyword");//关键词
						if(iThFora.get("depth").equals("0"))
						{
							//System.out.println("开始查看["+0+"(+"+forti+"+)]{"+forthi+"}【"+thkeyword+"】\n"+thcontent+"\n("+tholdcontent+")\n");
							//System.out.println("开始查看["+SourceHtml+"]\n");
							//this.returnS=this.returnS+thcontent;
							GyReplace gyr = new GyReplace();
							SourceHtml=gyr.replace(SourceHtml, gytFrontSeparator+"for:" + thkeyword + gytBackSeparator +tholdcontent + gytFrontSeparator+"endfor:" + thkeyword + gytBackSeparator, thcontent);
							
						}
					}
		
				}
			//}
			this.returnS=SourceHtml;
			
		}
	}
	
	
	
	@SuppressWarnings("unused")
	public void ParseFor(String gytFrontSeparator,String gytBackSeparator,String gytPFrontSeparator,String gytPBackSeparator,HashMap<String, ArrayList<HashMap<String, String>>> gytInFor)
	{
		
		int NumFor=0;
		int maxDepth=0;
		String forhead="";
		String forfoot="";
		
		String SourceHtml="";
		SourceHtml=this.currnS;
		
		String[] tempContent = null;
		
		GyLinkTables head = null;
		GyLinkTables CL = new GyLinkTables();
		
		GySplit a = new GySplit();
		a.tool(this.currnS, gytFrontSeparator+"for:");
		tempContent = a.Show();
		a = null;
		//System.out.println("查看源代码：："+tempContent.length);
		//查找是否有for，如果没有的话，跳过以下的步骤
		if(tempContent.length<=1)
		{
			this.returnS=this.currnS;
		}
		else
		{
			//修复取出尾部
			String[] tempContentfoot = null;
			GySplit z = new GySplit();
			z.tool(tempContent[(tempContent.length-1)], gytFrontSeparator+"endfor:");
			tempContentfoot = z.Show();
			z = null;
			//System.out.println("查看源代码：："+tempContent[(tempContent.length-1)]);
			//System.out.println("查看源代码1：："+tempContentfoot[1]);
			
			String[] tempContentfoot1 = null;
			GySplit z1 = new GySplit();
			z1.tool(tempContentfoot[1], gytBackSeparator);
			tempContentfoot1 = z1.Show();
			z1 = null;
			
			//System.out.println("查看源代码2：："+tempContentfoot1[0]);
			
			//System.out.println("查看源代码1：："+tempContent[(tempContent.length-1)]);
			//修复取出尾部
			String[] tempContentfoot2 = null;
			GySplit z2 = new GySplit();
			z2.tool(tempContent[(tempContent.length-1)], gytFrontSeparator+"endfor:"+tempContentfoot1[0]+gytBackSeparator);
			tempContentfoot2 = z2.Show();
			z2 = null;
			
			forhead=tempContent[0];
			forfoot=tempContentfoot2[1];
			//取尾巴的内容
			
			//修复成功
			
			//
			NumFor=tempContent.length-1;
			for(int i=0;i<NumFor;i++)
			{
				String tempcuurS="";
				String keyword="";
				String Content="";
				//
				for(int j=i;j<NumFor;j++)
				{
					tempcuurS=tempcuurS+tempContent[j+1]+gytFrontSeparator+"for:";
				}
				
				//System.out.println("[[["+i+"]]]tempcuurS============"+tempcuurS);
				
				String[] tempContentB = null;
				GySplit b = new GySplit();
				b.tool(tempcuurS, gytBackSeparator);
				tempContentB = b.Show();
				b = null;
				keyword=tempContentB[0];
				//System.out.println("[[["+i+"]]]keyword============"+keyword);
				String[] tempContentC = null;
				GySplit c = new GySplit();
				c.tool(tempcuurS, gytFrontSeparator+"endfor:"+keyword+gytBackSeparator);
				tempContentC = c.Show();
				c = null;
				
				Content=tempContentC[0];
				
				GyReplace gyr=new GyReplace();
				Content=gyr.replace(Content, keyword+gytBackSeparator, "");
				
				//添加前先便利更新深度
				
				GyLinkTables htemp = null;
				GyForData tempnodeData ;
				htemp = head;
				
				int cdepth=0;
				
				while(htemp != null)							//循环处理链表每个结点
				{
					tempnodeData = htemp.nodeData;
					
					String[] tempContentD = null;
					GySplit d = new GySplit();
					d.tool(tempnodeData.content, gytFrontSeparator+"for:"+keyword+gytBackSeparator);
					tempContentD = d.Show();
					d = null;
					
					if(tempContentD.length<2)
					{
						
					}
					else
					{
						cdepth=cdepth+1;
						if(maxDepth>cdepth)
						{
							
						}
						else
						{
							maxDepth=cdepth;
						}
					}
					
					htemp = htemp.nextNode;
				}
				
				
				//System.out.println("[[["+i+"]]]Content============"+Content);
				GyForData nodeData = new GyForData();
				nodeData.id=i;
				nodeData.keyword=keyword;
				nodeData.content=Content;
				nodeData.depth=cdepth;
				head = CL.CLAddEnd(head, nodeData);//在链表尾部添加结点
			}
			//System.out.println("[[]]maxDepth============"+maxDepth);
			//CL.CLAllNode(head);
			
			//ArrayList<Map<String, String>> forb=new ArrayList<Map<String, String>>();
			GyArrayList[] tempfor;
			tempfor=new GyArrayList[(maxDepth+1)];
			for(int fi=maxDepth;fi>=0;fi--)
			{
				//System.out.println("[[[[[]]]]]]]]]]]]]+++++++"+fi);
				GyLinkTables forhtemp;
				GyForData fornodeData ;
				forhtemp = head;
				GyArrayList forMain=new GyArrayList();
				ArrayList<ArrayList<Map<String,String>>> forc=new ArrayList<ArrayList<Map<String,String>>>();
				while(forhtemp != null)							//循环处理链表每个结点
				{
					fornodeData = forhtemp.nodeData;
					//System.out.println("关键词["+fornodeData.keyword+"]");
					if(fornodeData.depth==fi)
					{
						if(fornodeData.depth==maxDepth)
						{
							//是最里层
							//只是循环，不做其它的处理
							ArrayList<Map<String,String>> forb=new ArrayList<Map<String,String>>();
							Map<String,String> fora=new HashMap<String,String>();
							//System.out.println("处理2");
							GyGetFor ggf=new GyGetFor();
							ggf.setcurrnS(fornodeData.content);
							
							//对keyword进行判断，看看有没有步长
							if(fornodeData.keyword.indexOf("[")<0)
							{
								ggf.ParseFor(gytPFrontSeparator, gytPBackSeparator, gytInFor, fornodeData.keyword);
							}
							else
							{
								
								String stepnum="0";
								String tkey="";
								//获取关键词和步长
								String[] tempStepMain = null;
								GySplit mm = new GySplit();
								mm.tool(fornodeData.keyword, "[");
								tempStepMain = mm.Show();
								mm = null;
								
								tkey=tempStepMain[0];
								stepnum=tempStepMain[1];
								
								String[] tempStepMain1 = null;
								GySplit mm1= new GySplit();
								mm1.tool(stepnum, "]");
								tempStepMain1 = mm1.Show();
								mm1 = null;
								
								stepnum=tempStepMain1[0];
								//
								ggf.ParseForStep(gytPFrontSeparator, gytPBackSeparator, gytInFor, tkey ,stepnum);
							}
							
							//ggf.ParseFor(gytPFrontSeparator, gytPBackSeparator, gytInFor, fornodeData.keyword);
							fora.put("content", ggf.getsContent());
							fora.put("oldcontent", fornodeData.content);
							fora.put("id", fornodeData.id+"");
							fora.put("keyword", fornodeData.keyword);
							fora.put("depth", fornodeData.depth+"");
							forb.add(fora);
							//forMain.setArrayList(fora);
							forc.add(forb);
						}
						else
						{
							//如果不是最里层
							//则先处理最和外层的关系
							//首先取得下一层中所有已经替换的数据
							//当前变量
							String cqcontent=fornodeData.content;
							String cqkeyword=fornodeData.keyword;
							int cqid=fornodeData.id;
							int cqdepth=fornodeData.depth;
							
							for(int forti=0;forti<tempfor[(fi+1)].getForArrayList().size();forti++)
							{
								//判断当前的变量中是否含有下一层中的关键词，即是否替换for变量
								ArrayList<Map<String,String>> ThFora=new ArrayList<Map<String,String>>();
								ThFora=tempfor[(fi+1)].getForArrayList().get(forti);
								for(int forthi=0;forthi<ThFora.size();forthi++)
								{
									HashMap<String, String> iThFora = (HashMap<String, String>) ThFora.get(forthi);
									
									String thcontent=iThFora.get("content");//替换过的内容，
									String tholdcontent=iThFora.get("oldcontent");//未替换的内容
									String thkeyword=iThFora.get("keyword");//关键词
									//System.out.println("查找"+gytFrontSeparator+"for:" +thkeyword +gytBackSeparator+"");
									String[] tempContentE = null;
									GySplit e = new GySplit();
									e.tool(cqcontent, gytFrontSeparator+"for:" +thkeyword +gytBackSeparator);
									tempContentE = e.Show();
									e = null;
									if(tempContentE.length<2)
									{
										//没有找到
									}
									else
									{
										//找到替换
										//System.out.println("把｛"+tholdcontent+"｝替换成【"+thcontent+"】");
										
										GyReplace r = new GyReplace();
										r.replaceAll(cqcontent, gytFrontSeparator+"for:" +thkeyword +gytBackSeparator+tholdcontent+gytFrontSeparator+"endfor:" +thkeyword +gytBackSeparator, thcontent);
										cqcontent=r.Show();
									}
								}
							}
							
							ArrayList<Map<String,String>> forb=new ArrayList<Map<String,String>>();
							Map<String,String> fora=new HashMap<String,String>();
							//System.out.println("处理2");
							GyGetFor ggf=new GyGetFor();
							ggf.setcurrnS(cqcontent);
							//对keyword进行判断，看看有没有步长
							if(fornodeData.keyword.indexOf("[")<0)
							{
								ggf.ParseFor(gytPFrontSeparator, gytPBackSeparator, gytInFor, fornodeData.keyword);
							}
							else
							{
								String stepnum="0";
								String tkey="";
								//获取关键词和步长
								String[] tempStepMain = null;
								GySplit mm = new GySplit();
								mm.tool(fornodeData.keyword, "[");
								tempStepMain = mm.Show();
								mm = null;
								
								tkey=tempStepMain[0];
								stepnum=tempStepMain[1];
								
								String[] tempStepMain1 = null;
								GySplit mm1= new GySplit();
								mm1.tool(stepnum, "]");
								tempStepMain1 = mm1.Show();
								mm1 = null;
								
								stepnum=tempStepMain1[0];
								//
								ggf.ParseForStep(gytPFrontSeparator, gytPBackSeparator, gytInFor, tkey ,stepnum);
							}

							fora.put("content", ggf.getsContent());
							fora.put("oldcontent", fornodeData.content);
							fora.put("id", fornodeData.id+"");
							fora.put("keyword", fornodeData.keyword);
							fora.put("depth", fornodeData.depth+"");
							forb.add(fora);
							//forMain.setArrayList(fora);
							forc.add(forb);
						}
					}
					
					forhtemp = forhtemp.nextNode;
				}
				forMain.setArrayList(forc);
				tempfor[fi]=forMain;
			}
			this.returnS=forhead;
			
			//for(int tti=0;tti<(maxDepth+1);tti++)
			//{
				for(int forti=0;forti<tempfor[0].getForArrayList().size();forti++)
				{
					//判断当前的变量中是否含有下一层中的关键词，即是否替换for变量
					ArrayList<Map<String,String>> ThFora=new ArrayList<Map<String,String>>();
					ThFora=tempfor[(0)].getForArrayList().get(forti);
					for(int forthi=0;forthi<ThFora.size();forthi++)
					{
						HashMap<String, String> iThFora = (HashMap<String, String>) ThFora.get(forthi);
						
						String thcontent=iThFora.get("content");//替换过的内容，
						String tholdcontent=iThFora.get("oldcontent");//未替换的内容
						String thkeyword=iThFora.get("keyword");//关键词
						if(iThFora.get("depth").equals("0"))
						{
							//System.out.println("开始查看["+0+"(+"+forti+"+)]{"+forthi+"}【"+thkeyword+"】\n"+thcontent+"\n");
							//this.returnS=this.returnS+thcontent;
							//System.out.println("开始查看["+0+"(+"+forti+"+)]{"+forthi+"}【"+thkeyword+"】\n"+thcontent+"\n("+tholdcontent+")\n");
							//System.out.println("开始查看["+SourceHtml+"]\n");
							//this.returnS=this.returnS+thcontent;
							GyReplace gyr = new GyReplace();
							SourceHtml=gyr.replace(SourceHtml, gytFrontSeparator+"for:" + thkeyword + gytBackSeparator +tholdcontent + gytFrontSeparator+"endfor:" + thkeyword + gytBackSeparator, thcontent);

						}
					}
		
				}
			//}
			this.returnS=SourceHtml;
		}
	}
	
	public String getcurrnS()
	{
		return this.currnS;
	}
	
	public String getreturnS()
	{
		return this.returnS;
	}
}
